home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / lib / tclX6.4c / dist / tests / loop.test < prev    next >
Encoding:
Text File  |  1992-11-07  |  2.6 KB  |  134 lines

  1. #
  2. # loop.test
  3. #
  4. # Tests for the loop command.
  5. #---------------------------------------------------------------------------
  6. # Copyright 1992 Karl Lehenbauer and Mark Diekhans.
  7. #
  8. # Permission to use, copy, modify, and distribute this software and its
  9. # documentation for any purpose and without fee is hereby granted, provided
  10. # that the above copyright notice appear in all copies.  Karl Lehenbauer and
  11. # Mark Diekhans make no representations about the suitability of this
  12. # software for any purpose.  It is provided "as is" without express or
  13. # implied warranty.
  14. #------------------------------------------------------------------------------
  15. # $Id: loop.test,v 2.0 1992/10/16 04:50:01 markd Rel $
  16. #------------------------------------------------------------------------------
  17. #
  18.  
  19. if {[info procs test] != "test"} then {source testlib.tcl}
  20.  
  21. test loop-1.1 {loop tests} {
  22.     set a {}
  23.     set i 1
  24.     loop i 1 6 {
  25.         set a [concat $a $i]
  26.     }
  27.     set a
  28. } {1 2 3 4 5}
  29.  
  30. test loop-1.2 {loop tests} {
  31.     set a {}
  32.     loop i 1 6 {
  33.         if {$i == 4} {
  34.             continue}
  35.         set a [concat $a $i]
  36.     }
  37.     set a
  38. } {1 2 3 5}
  39.  
  40. test loop-1.3 {loop tests} {
  41.     set a {}
  42.     loop i 1 6 {
  43.         if $i==4 break
  44.         set a [concat $a $i]
  45.     }
  46.     set a
  47. } {1 2 3}
  48.  
  49. test loop-1.4 {loop tests} {
  50.     list [catch {loop 1 2 3} msg] $msg
  51. } {1 {wrong # args: loop var first limit [incr] command}}
  52. test loop-1.5 {loop tests} {
  53.     list [catch {loop 1 2 3 4 5 6} msg] $msg
  54. } {1 {wrong # args: loop var first limit [incr] command}}
  55.  
  56. test loop-1.6 {loop tests} {
  57.     set a {}
  58.     loop i 1 6 {
  59.         set a [concat $a $i]
  60.         set i 100
  61.     }
  62.     set a
  63. } {1 2 3 4 5}
  64.  
  65. test loop-1.7 {loop tests} {
  66.     set a {}
  67.     loop i 1 6 2 {
  68.         set a [concat $a $i]
  69.     }
  70.     set a
  71. } {1 3 5}
  72.  
  73. test loop-1.8 {loop tests} {
  74.     set a {}
  75.     set i 1
  76.     loop i 6 1 -1 {
  77.         set a [concat $a $i]
  78.     }
  79.     set a
  80. } {6 5 4 3 2}
  81.  
  82. test loop-1.9 {loop tests} {
  83.     set a {}
  84.     loop i 6 1 -1 {
  85.         if $i==4 {
  86.             continue}
  87.         set a [concat $a $i]
  88.     }
  89.     set a
  90. } {6 5 3 2}
  91.  
  92. test loop-1.10 {loop tests} {
  93.     set a {}
  94.     loop i 6 1 -1 {
  95.         if {$i == 4} {
  96.             break}
  97.         set a [concat $a $i]
  98.     }
  99.     set a
  100. } {6 5}
  101.  
  102. test loop-1.11 {loop tests} {
  103.     set j 0
  104.     loop i 65536 65556 {
  105.         incr j
  106.     }
  107.     set j
  108. } 20
  109.  
  110. test loop-1.12 {loop tests} {
  111.     set j 0
  112.     loop i 65556 65536 -1 {
  113.         incr j 1
  114.     }
  115.     set j
  116. } 20
  117.  
  118. test loop-1.13 {loop tests} {
  119.     set j 0
  120.     loop i 0 655360 65536 {
  121.         incr j 1
  122.     }
  123.     set j
  124. } 10
  125.  
  126. test loop-1.13 {loop tests} {
  127.     set j 0
  128.     loop i 655360 0 -65536 {
  129.         incr j 1
  130.     }
  131.     set j
  132. } 10
  133.  
  134.